package com.wt.springsamples.biz.service.impl;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.wt.springsamples.model.IEntity;
import com.wt.springsamples.biz.service.IBaseService;

import java.util.List;

public abstract  class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M,T> implements IBaseService<T> {

    @Override
    public <E extends IEntity> void saveBatch(Class<E> entityClass, List<E> entityList) {
        String sqlStatement = SqlHelper.table(entityClass).getSqlStatement(SqlMethod.INSERT_ONE.getMethod());
//        String sqlStatement = SqlHelper.getSqlStatement(BaseMapper.class, SqlMethod.INSERT_ONE);//需要指定实体对象对应的Mapper
        SqlHelper.executeBatch(entityClass,log,entityList,entityList.size(),(sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
    }
}
